package com.chonor.mall.service.impl;

import com.chonor.mall.mapper.MemberLevelMapper;
import com.chonor.mall.model.MemberLevel;
import com.chonor.mall.model.MemberLevelExample;
import com.chonor.mall.service.MemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 会员等级管理Service实现类
 */
@Service
public class MemberLevelServiceImpl implements MemberLevelService {
    @Autowired
    private MemberLevelMapper memberLevelMapper;

    @Override
    public List<MemberLevel> list() {
        return memberLevelMapper.selectByExample(new MemberLevelExample());
    }

    @Override
    public int create(MemberLevel memberLevel) {
        return memberLevelMapper.insert(memberLevel);
    }

    @Override
    public MemberLevel getItem(Long id) {
        return memberLevelMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(Long id, MemberLevel memberLevel) {
        memberLevel.setId(id);
        return memberLevelMapper.updateByPrimaryKeySelective(memberLevel);
    }

    @Override
    public int delete(Long id) {
        MemberLevelExample example = new MemberLevelExample();
        example.createCriteria().andIdEqualTo(id);
        return memberLevelMapper.deleteByExample(example);
    }
}
